﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;

namespace Manager
{
	// Token: 0x020002BF RID: 703
	public class Character : global::Singleton<Character>
	{
		// Token: 0x17000269 RID: 617
		// (get) Token: 0x06001126 RID: 4390 RVA: 0x00088DBC File Offset: 0x00086FBC
		// (set) Token: 0x06001127 RID: 4391 RVA: 0x00088DC4 File Offset: 0x00086FC4
		public global::CharaListInfo charaListInfo { get; set; }

		// Token: 0x1700026A RID: 618
		// (get) Token: 0x06001128 RID: 4392 RVA: 0x00088DD0 File Offset: 0x00086FD0
		// (set) Token: 0x06001129 RID: 4393 RVA: 0x00088DD8 File Offset: 0x00086FD8
		public Dictionary<string, Material> dictSiruMaterial { get; set; }

		// Token: 0x1700026B RID: 619
		// (get) Token: 0x0600112A RID: 4394 RVA: 0x00088DE4 File Offset: 0x00086FE4
		// (set) Token: 0x0600112B RID: 4395 RVA: 0x00088DEC File Offset: 0x00086FEC
		public SortedDictionary<int, global::CharFemale> dictFemale { get; set; }

		// Token: 0x1700026C RID: 620
		// (get) Token: 0x0600112C RID: 4396 RVA: 0x00088DF8 File Offset: 0x00086FF8
		// (set) Token: 0x0600112D RID: 4397 RVA: 0x00088E00 File Offset: 0x00087000
		public SortedDictionary<int, global::CharMale> dictMale { get; set; }

		// Token: 0x0600112E RID: 4398 RVA: 0x00088E0C File Offset: 0x0008700C
		public virtual void BeginLoadAssetBundle()
		{
			this.dictLoadAssetBundleName.Clear();
			this.loadAssetBundle = true;
		}

		// Token: 0x0600112F RID: 4399 RVA: 0x00088E20 File Offset: 0x00087020
		public virtual void AddLoadAssetBundle(string assetBundleName)
		{
			this.dictLoadAssetBundleName[assetBundleName] = true;
		}

		// Token: 0x06001130 RID: 4400 RVA: 0x00088E30 File Offset: 0x00087030
		public virtual void EndLoadAssetBundle()
		{
			foreach (KeyValuePair<string, bool> keyValuePair in this.dictLoadAssetBundleName)
			{
				global::AssetBundleManager.UnloadAssetBundle(keyValuePair.Key, true, null);
			}
			Resources.UnloadUnusedAssets();
			GC.Collect();
			this.dictLoadAssetBundleName.Clear();
			this.loadAssetBundle = false;
		}

		// Token: 0x06001131 RID: 4401 RVA: 0x00088EB0 File Offset: 0x000870B0
		public virtual global::CharFemale CreateFemale(GameObject parent, int id, global::CharFemaleFile _chafile = null)
		{
			int num = this.SearchUnusedNo(1);
			GameObject gameObject = new GameObject("chaF" + num.ToString("00"));
			if (parent)
			{
				gameObject.transform.SetParent(parent.transform, false);
			}
			global::CharFemale charFemale = gameObject.AddComponent<global::CharFemale>();
			if (charFemale)
			{
				charFemale.Initialize(gameObject, id, num, _chafile);
			}
			this.dictFemale.Add(num, charFemale);
			return charFemale;
		}

		// Token: 0x06001132 RID: 4402 RVA: 0x00088F28 File Offset: 0x00087128
		public virtual global::CharMale CreateMale(GameObject parent, int id = -1, global::CharMaleFile _chafile = null)
		{
			int num = this.SearchUnusedNo(0);
			GameObject gameObject = new GameObject("chaM" + num.ToString("00"));
			if (parent)
			{
				gameObject.transform.SetParent(parent.transform, false);
			}
			global::CharMale charMale = gameObject.AddComponent<global::CharMale>();
			if (charMale)
			{
				charMale.Initialize(gameObject, id, num, _chafile);
			}
			this.dictMale.Add(num, charMale);
			return charMale;
		}

		// Token: 0x06001133 RID: 4403 RVA: 0x00088FA0 File Offset: 0x000871A0
		public virtual bool DeleteFemale(global::CharFemale cha)
		{
			foreach (KeyValuePair<int, global::CharFemale> keyValuePair in this.dictFemale)
			{
				if (keyValuePair.Value == cha)
				{
					if (keyValuePair.Value)
					{
						UnityEngine.Object.Destroy(keyValuePair.Value.gameObject);
					}
					this.dictFemale.Remove(keyValuePair.Key);
					return true;
				}
			}
			return false;
		}

		// Token: 0x06001134 RID: 4404 RVA: 0x00089044 File Offset: 0x00087244
		public virtual bool DeleteMale(global::CharMale cha)
		{
			foreach (KeyValuePair<int, global::CharMale> keyValuePair in this.dictMale)
			{
				if (keyValuePair.Value == cha)
				{
					if (keyValuePair.Value)
					{
						UnityEngine.Object.Destroy(keyValuePair.Value.gameObject);
					}
					this.dictMale.Remove(keyValuePair.Key);
					return true;
				}
			}
			return false;
		}

		// Token: 0x06001135 RID: 4405 RVA: 0x000890E8 File Offset: 0x000872E8
		public virtual void DeleteFemaleAll()
		{
			foreach (KeyValuePair<int, global::CharFemale> keyValuePair in this.dictFemale)
			{
				if (keyValuePair.Value)
				{
					UnityEngine.Object.Destroy(keyValuePair.Value.gameObject);
				}
			}
			this.dictFemale.Clear();
		}

		// Token: 0x06001136 RID: 4406 RVA: 0x00089168 File Offset: 0x00087368
		public virtual void DeleteMaleAll()
		{
			foreach (KeyValuePair<int, global::CharMale> keyValuePair in this.dictMale)
			{
				if (keyValuePair.Value)
				{
					UnityEngine.Object.Destroy(keyValuePair.Value.gameObject);
				}
			}
			this.dictMale.Clear();
		}

		// Token: 0x06001137 RID: 4407 RVA: 0x000891E8 File Offset: 0x000873E8
		public virtual global::CharFemale GetFemale(int _id)
		{
			try
			{
				return this.dictFemale.First((KeyValuePair<int, global::CharFemale> v) => v.Value.CharID == _id).Value;
			}
			catch (ArgumentNullException ex)
			{
			}
			catch (InvalidOperationException ex2)
			{
			}
			return null;
		}

		// Token: 0x06001138 RID: 4408 RVA: 0x0008925C File Offset: 0x0008745C
		public static void ChangeRootParentFemale(global::CharFemale female, GameObject newParent)
		{
			if (null == female)
			{
				return;
			}
			female.gameObject.transform.SetParent(newParent.transform, false);
		}

		// Token: 0x06001139 RID: 4409 RVA: 0x00089284 File Offset: 0x00087484
		public static void ChangeRootParentMale(global::CharMale male, GameObject newParent)
		{
			if (null == male)
			{
				return;
			}
			male.gameObject.transform.SetParent(newParent.transform, false);
		}

		// Token: 0x0600113A RID: 4410 RVA: 0x000892AC File Offset: 0x000874AC
		public new virtual void Awake()
		{
			if (!base.CheckInstance())
			{
				return;
			}
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			this.charaListInfo = new global::CharaListInfo();
			this.dictSiruMaterial = new Dictionary<string, Material>();
			this.dictFemale = new SortedDictionary<int, global::CharFemale>();
			this.dictMale = new SortedDictionary<int, global::CharMale>();
			this.charaListInfo.LoadListInfoAll();
			string[,] array = new string[5, 2];
			array[0, 0] = "cf_M_k_kaosiru00";
			array[0, 1] = "cf_M_k_kaosiru01";
			array[1, 0] = "cf_M_k_munesiru00";
			array[1, 1] = "cf_M_k_munesiru01";
			array[2, 0] = "cf_M_k_matasiru00";
			array[2, 1] = "cf_M_k_matasiru01";
			array[3, 0] = "cf_M_k_senakasiru00";
			array[3, 1] = "cf_M_k_senakasiru01";
			array[4, 0] = "cf_M_k_sirisiru00";
			array[4, 1] = "cf_M_k_sirisiru01";
			string[,] array2 = array;
			string assetBundleName = "chara/cf_m_base.unity3d";
			int num = 0;
			foreach (object obj in Enum.GetValues(typeof(global::CharDefine.SiruParts)))
			{
				for (int i = 0; i < 2; i++)
				{
					string key = obj.ToString() + (i + 1).ToString("00");
					this.dictSiruMaterial[key] = global::CommonLib.LoadAsset<Material>(assetBundleName, array2[num, i], false, string.Empty);
				}
				num++;
			}
			global::AssetBundleManager.UnloadAssetBundle(assetBundleName, true, null);
			this._MainTex = Shader.PropertyToID("_MainTex");
			this._Texture2 = Shader.PropertyToID("_Texture2");
			this._Texture3 = Shader.PropertyToID("_Texture3");
			this._Texture4 = Shader.PropertyToID("_Texture4");
			this._Texture5 = Shader.PropertyToID("_Texture5");
			this._Texture6 = Shader.PropertyToID("_Texture6");
			this._Texture7 = Shader.PropertyToID("_Texture7");
			this._Color = Shader.PropertyToID("_Color");
			this._Color2 = Shader.PropertyToID("_Color2");
			this._Color3 = Shader.PropertyToID("_Color3");
			this._Color4 = Shader.PropertyToID("_Color4");
			this._Color5 = Shader.PropertyToID("_Color5");
			this._Color6 = Shader.PropertyToID("_Color6");
			this._Color7 = Shader.PropertyToID("_Color7");
			this._SpecColor = Shader.PropertyToID("_SpecColor");
			this._Metallic = Shader.PropertyToID("_Metallic");
			this._Smoothness = Shader.PropertyToID("_Smoothness");
			this._Color_3 = Shader.PropertyToID("_Color_3");
			this._SpecColor_3 = Shader.PropertyToID("_SpecColor_3");
			this._BumpMap = Shader.PropertyToID("_BumpMap");
			this._BlendNormalMap = Shader.PropertyToID("_BlendNormalMap");
			this._BlendNormalMapScale = Shader.PropertyToID("_BlendNormalMapScale");
		}

		// Token: 0x0600113B RID: 4411 RVA: 0x000895B8 File Offset: 0x000877B8
		public virtual int SearchUnusedNo(byte sex)
		{
			int num = 0;
			if (sex == 1)
			{
				foreach (KeyValuePair<int, global::CharFemale> keyValuePair in this.dictFemale)
				{
					if (num != keyValuePair.Key)
					{
						break;
					}
					num++;
				}
				return num;
			}
			foreach (KeyValuePair<int, global::CharMale> keyValuePair2 in this.dictMale)
			{
				if (num != keyValuePair2.Key)
				{
					break;
				}
				num++;
			}
			return num;
		}

		// Token: 0x0600113C RID: 4412 RVA: 0x00089688 File Offset: 0x00087888
		public static int ConvertSBPRData()
		{
			int num = 0;
			string str = DateTime.Now.ToString("yyyyMMddHHmmssfff");
			global::FolderAssist folderAssist = new global::FolderAssist();
			string folder = global::UserData.Path + "chara/male/";
			string[] searchPattern = new string[]
			{
				"*.png"
			};
			folderAssist.CreateFolderInfoEx(folder, searchPattern, true);
			int fileCount = folderAssist.GetFileCount();
			string text = string.Empty;
			for (int i = 0; i < fileCount; i++)
			{
				text = folderAssist.lstFile[i].FullPath;
				if (global::CharFile.CheckSBPRFile(text))
				{
					global::CharMaleFile charMaleFile = new global::CharMaleFile();
					global::CharFile charFile = charMaleFile;
					if (charFile.LoadFromSBPR(text))
					{
						charFile.Save(text);
						string str2 = Path.GetDirectoryName(text) + "/";
						string str3 = str + "_" + num.ToString() + ".png";
						string destFileName = string.Empty;
						destFileName = str2 + "/sbpr_m_" + str3;
						File.Move(text, destFileName);
						num++;
					}
				}
			}
			global::FolderAssist folderAssist2 = new global::FolderAssist();
			string folder2 = global::UserData.Path + "chara/female/";
			string[] searchPattern2 = new string[]
			{
				"*.png"
			};
			folderAssist2.CreateFolderInfoEx(folder2, searchPattern2, true);
			int fileCount2 = folderAssist2.GetFileCount();
			string text2 = string.Empty;
			for (int j = 0; j < fileCount2; j++)
			{
				text2 = folderAssist2.lstFile[j].FullPath;
				if (global::CharFile.CheckSBPRFile(text2))
				{
					global::CharFemaleFile charFemaleFile = new global::CharFemaleFile();
					global::CharFile charFile = charFemaleFile;
					if (charFile.LoadFromSBPR(text2))
					{
						charFile.Save(text2);
						string str4 = Path.GetDirectoryName(text2) + "/";
						string str5 = str + "_" + num.ToString() + ".png";
						string destFileName2 = string.Empty;
						destFileName2 = str4 + "/sbpr_f_" + str5;
						File.Move(text2, destFileName2);
						num++;
					}
				}
			}
			return num;
		}

		// Token: 0x040016D9 RID: 5849
		public bool ignoreConfig;

		// Token: 0x040016DA RID: 5850
		public int _MainTex;

		// Token: 0x040016DB RID: 5851
		public int _Texture2;

		// Token: 0x040016DC RID: 5852
		public int _Texture3;

		// Token: 0x040016DD RID: 5853
		public int _Texture4;

		// Token: 0x040016DE RID: 5854
		public int _Texture5;

		// Token: 0x040016DF RID: 5855
		public int _Texture6;

		// Token: 0x040016E0 RID: 5856
		public int _Texture7;

		// Token: 0x040016E1 RID: 5857
		public int _Color;

		// Token: 0x040016E2 RID: 5858
		public int _Color2;

		// Token: 0x040016E3 RID: 5859
		public int _Color3;

		// Token: 0x040016E4 RID: 5860
		public int _Color4;

		// Token: 0x040016E5 RID: 5861
		public int _Color5;

		// Token: 0x040016E6 RID: 5862
		public int _Color6;

		// Token: 0x040016E7 RID: 5863
		public int _Color7;

		// Token: 0x040016E8 RID: 5864
		public int _SpecColor;

		// Token: 0x040016E9 RID: 5865
		public int _Metallic;

		// Token: 0x040016EA RID: 5866
		public int _Smoothness;

		// Token: 0x040016EB RID: 5867
		public int _Color_3;

		// Token: 0x040016EC RID: 5868
		public int _SpecColor_3;

		// Token: 0x040016ED RID: 5869
		public int _BumpMap;

		// Token: 0x040016EE RID: 5870
		public int _BlendNormalMap;

		// Token: 0x040016EF RID: 5871
		public int _BlendNormalMapScale;

		// Token: 0x040016F0 RID: 5872
		public Dictionary<string, bool> dictLoadAssetBundleName = new Dictionary<string, bool>();

		// Token: 0x040016F1 RID: 5873
		public bool loadAssetBundle;
	}
}
